package com.deng.common.dao.impl;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.deng.common.SQLHelper;
import com.deng.common.dao.IOrganizationPerformance;
import com.deng.common.vo.OrganizationVo;
import com.deng.common.vo.OrganizationVsPerformanceVo;

public class OrganizationPerformanceImpl extends SQLHelper implements
		IOrganizationPerformance {

	public OrganizationVo setOrganizationPerformance(OrganizationVo vo) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public OrganizationVo updateOrganizationPerformance(OrganizationVo vo) {
		// TODO Auto-generated method stub
		try{			
			Connection conn = getConnect();
			updateData(conn,"delete DICT_ORGANIZATION_VS_PERFORMANCE " +
					"	where organization_id = "+vo.id);
			if(vo.organization_vs_performance_arr != null && vo.organization_vs_performance_arr.size() > 0){				
				for(int i = 0;i< vo.organization_vs_performance_arr.size();i++){
					conn = getConnect();
					OrganizationVsPerformanceVo ovp = vo.organization_vs_performance_arr.get(i);
					BigDecimal weight = new BigDecimal(0);
					if(ovp.weight != null){
						weight = new BigDecimal(ovp.weight).divide(new BigDecimal(100));
					}
					updateData(conn,"insert into DICT_ORGANIZATION_VS_PERFORMANCE " +
							"	(organization_id,organization_name,performance_id,performance_name,weight)" +
							"	values ("+ovp.organization_id+",'"+ovp.organization_name+"',"
							+ovp.performance_id+",'"+ovp.performance_name+"',"+weight+")");
					freeConnection(conn);
				}
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}

//	public List<OrganizationVsPerformanceVo> getOrganizationPerformanceList(
//			OrganizationVo vo) {
//		// TODO Auto-generated method stub
//		try{			
//			Connection conn = getConnect();
//			ResultSet rs = queryData(conn,"select DICT_PERFORMANCE_TYPE.id,DICT_PERFORMANCE_TYPE.name,			" +
//					"DICT_ORGANIZATION_VS_PERFORMANCE.organization_id,DICT_ORGANIZATION_VS_PERFORMANCE.organization_name,			" +
//					"DICT_ORGANIZATION_VS_PERFORMANCE.weight	" +
//					" from DICT_PERFORMANCE_TYPE			" +
//					"left join DICT_ORGANIZATION_VS_PERFORMANCE			" +
//					"on DICT_ORGANIZATION_VS_PERFORMANCE.performance_id = DICT_PERFORMANCE_TYPE.id			" +
//					"and DICT_ORGANIZATION_VS_PERFORMANCE.organization_id = " +vo.id+"	"+
//					"order by id");
//			
//			
//			
////			ResultSet rs = queryData("select * from DICT_ORGANIZATION_VS_PERFORMANCE where organization_id = "+vo.id);
//			List<OrganizationVsPerformanceVo> list = new ArrayList<OrganizationVsPerformanceVo>();
//			while(rs.next()){
//				OrganizationVsPerformanceVo tvo = new OrganizationVsPerformanceVo();
//				tvo.organization_id = vo.id;
//				tvo.organization_name = vo.name;
//				tvo.performance_id = rs.getInt("id");
//				tvo.performance_name = rs.getString("name");
//				if(rs.getBigDecimal("weight") != null){
//					tvo.weight = (rs.getBigDecimal("weight").multiply(new BigDecimal(100)))+"";
//				}else{
//					tvo.weight = "0";
//				}				
//				list.add(tvo);
//			}
//			freeConnection(conn);
//			return list;
//		}catch(Exception ex){
//			ex.printStackTrace();
//		}
//		return null;
//	}
//	
//	public List<OrganizationVsPerformanceVo> getPerformance(){
//		try{			
//			Connection conn = getConnect();
//			ResultSet rs = queryData(conn,"select * from DICT_PERFORMANCE_TYPE order by id");
//			List<OrganizationVsPerformanceVo> list = new ArrayList<OrganizationVsPerformanceVo>();
//			while(rs.next()){
//				OrganizationVsPerformanceVo tvo = new OrganizationVsPerformanceVo();
//				tvo.performance_id = rs.getInt("id");
//				tvo.performance_name = rs.getString("name");
//					
//				list.add(tvo);
//			}
//			freeConnection(conn);
//			return list;
//		}catch(Exception ex){
//			ex.printStackTrace();
//		}
//		return null;
//		
//	}

}
